import React, { useEffect, useState } from 'react';

import { getinto_list, getinto_list_delete, getinto_list_updata, getinto_list_create } from '../../utils/api/zqq/index'

import GetintoTop from './getIntoList/GetintoTop'
import GetintoList from './getIntoList/GetIntoList'
interface Props { }
function GetIntoList(props: Props) {
    const [lossList, setLossList]: any = useState([]);
    const getintolist = () => {
        getinto_list().then((res: any) => {
            console.log(res.data);
            setLossList(res.data)
            setPagination({ current: 1, pageSize: 5, total: res.data.total, })
        })
    }
    // 分页
    var [pagination, setPagination] = useState(
        {
            current: 1,
            pageSize: 5,
            total: 100,
        }
    )
    const handleChange = (pagination: any) => {
        setPagination(pagination)
        console.log(pagination);
        //pagination 参数 包含有当前最新页码

        //在这里发请求, 获取最新页码对应的数据

    }
    useEffect(() => {
        getintolist()
    }, [])

    const changelossList = (data: []) => {
        setLossList(data)
    }
    const indexdatadelete = (a: any) => {
        console.log('删除', a, a.id);
        getinto_list_delete(a.id).then((res: any) => {
            console.log(res.data);
            getintolist()
        })
    }

    const dataupdata = (values: Object) => {
        getinto_list_updata(values).then((res) => {
            console.log(res);
            getintolist()

        })
    }

    const datacreate = (value: Object) => {
        console.log(value);
        getinto_list_create(value).then((res) => {
            console.log(res);
            getintolist()
        })
    }

    return (
        <div>
            <GetintoTop getintolist={getintolist} datacreate={datacreate} changelossList={changelossList} />
            <GetintoList handleChange={handleChange} pagination={pagination} lossList={lossList} indexdatadelete={indexdatadelete} dataupdata={dataupdata} />
        </div>
    );
}

export default GetIntoList;